package cn.jtfadmin.base.dict.service.impl;

import cn.jtfadmin.base.dict.annotations.handle.DictSerializer;
import cn.jtfadmin.base.dict.dto.DictItemModelDTO;
import cn.jtfadmin.base.dict.dto.DictModelDTO;
import cn.jtfadmin.base.dict.service.DictConfig;
import cn.jtfadmin.base.lang.config.ObjectMapperConfig;
import cn.jtfadmin.base.lang.enums.BooleanEnum;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
@Configuration
public class BooleanEnumDictConfig implements DictConfig, ObjectMapperConfig {
    @Override
    public List<DictModelDTO> getInitDict() {
        return Arrays.asList(
                new DictModelDTO(BooleanEnum.class.getSimpleName(), "Boolean枚举",
                        Arrays.asList(
                                new DictItemModelDTO(BooleanEnum.TRUE.name(),"是"),
                                new DictItemModelDTO(BooleanEnum.FALSE.name(),"否")
                        )
                        )
        );
    }

    @Override
    public void doConfig(ObjectMapper objectMapper) {
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(BooleanEnum.class, new DictSerializer());
        objectMapper.registerModule(simpleModule);
    }
}
